package d20chat;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import java.io.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
 * A gui to set how text displays.
 */
public class UserOptions extends javax.swing.JFrame {
    
    /** The programs main class */
    D20Chat tempMain;
    /**
     * The color user chooses for messages from them.
     */
    private Color chatColor;
    /**
     * the color user chooses for non-user messages.
     */
    private Color defaultColor;
    /**
     * the color the user chooses for the background.
     */
    private Color defaultBackgroundColor;
    /**
     * the size the user chooses for messages from them.
     */
    private String chatSize = "";
    /**
     * the size the user chooses for non-user text.
     */
    private String displaySize = "";
    
    /**
     * Creates new form UserOptions.
     */
    public UserOptions() {
        initComponents();
        
        // Center User Options jFrame
        Dimension scrn = getToolkit().getScreenSize();
        this.setBounds( (scrn.width-getWidth())/2, (scrn.height-getHeight())/2, getWidth(), getHeight() );
    }
    
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
/**
     * Initilizes swing components.
     * This is generated code.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        titleLabel = new javax.swing.JLabel();
        saveButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        chatPanel = new javax.swing.JPanel();
        chatFontLabel = new javax.swing.JLabel();
        chatFontComboBox = new javax.swing.JComboBox();
        chatSizeLabel = new javax.swing.JLabel();
        chatColorLabel = new javax.swing.JLabel();
        chatColorButton = new javax.swing.JButton();
        cboChatSize = new javax.swing.JComboBox();
        chatColorShow = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        defaultPanel = new javax.swing.JPanel();
        overwriteCheckBox = new javax.swing.JCheckBox();
        defaultFontComboBox = new javax.swing.JComboBox();
        backgroundLabel = new javax.swing.JLabel();
        defaultFontSizeLabel = new javax.swing.JLabel();
        defaultFontColorLabel = new javax.swing.JLabel();
        defaultFontLabel = new javax.swing.JLabel();
        defaultFontColorButton = new javax.swing.JButton();
        defaultBackgroundButton = new javax.swing.JButton();
        cboDefaultSize = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        defaultFontColorShow = new javax.swing.JLabel();
        defaultBkgndColorShow = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        buffersize = new javax.swing.JTextField();
        restoreDefaults = new javax.swing.JButton();

        setTitle("User Options");
        setBackground(new java.awt.Color(204, 204, 204));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        titleLabel.setFont(new java.awt.Font("Tahoma", 1, 13));
        titleLabel.setText("Font Options");

        saveButton.setText("Save");
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });

        cancelButton.setText("Cancel");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        chatFontLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        chatFontLabel.setForeground(java.awt.Color.darkGray);
        chatFontLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        chatFontLabel.setText("Chat Font:");

        chatFontComboBox.setFont(new java.awt.Font("Tahoma", 0, 12));
        chatFontComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Arial", "Courier New", "Georgia", "Helveitca", "Tahoma", "Times", "Verdana" }));

        chatSizeLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        chatSizeLabel.setForeground(java.awt.Color.darkGray);
        chatSizeLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        chatSizeLabel.setText("Font Size:");

        chatColorLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        chatColorLabel.setForeground(java.awt.Color.darkGray);
        chatColorLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        chatColorLabel.setText("Font Color:");

        chatColorButton.setFont(new java.awt.Font("Tahoma", 0, 12));
        chatColorButton.setText("color");
        chatColorButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chatColorButtonActionPerformed(evt);
            }
        });

        cboChatSize.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "8pt", "9pt", "10pt", "12pt", "14pt", "16pt", "18pt", "20pt" }));

        chatColorShow.setOpaque(true);

        jLabel1.setText("Choose how messages coming from you will appear on everyone's screens:");

        javax.swing.GroupLayout chatPanelLayout = new javax.swing.GroupLayout(chatPanel);
        chatPanel.setLayout(chatPanelLayout);
        chatPanelLayout.setHorizontalGroup(
            chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(chatPanelLayout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addGroup(chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(chatFontLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(chatSizeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(chatColorLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(chatFontComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(chatPanelLayout.createSequentialGroup()
                        .addComponent(chatColorButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(chatColorShow, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(cboChatSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addGroup(chatPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1))
        );
        chatPanelLayout.setVerticalGroup(
            chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, chatPanelLayout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(chatFontComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(chatFontLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(chatPanelLayout.createSequentialGroup()
                        .addGroup(chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(chatSizeLabel)
                            .addComponent(cboChatSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(10, 10, 10)
                        .addGroup(chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(chatColorButton)
                            .addComponent(chatColorLabel)))
                    .addComponent(chatColorShow, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        overwriteCheckBox.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        overwriteCheckBox.setForeground(java.awt.Color.darkGray);
        overwriteCheckBox.setText("Overwrite all text formatting with default settings");
        overwriteCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        overwriteCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));

        defaultFontComboBox.setFont(new java.awt.Font("Tahoma", 0, 12));
        defaultFontComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Arial", "Courier New", "Georgia", "Helvetica", "Tahmoma", "Times", "Verdana" }));

        backgroundLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        backgroundLabel.setForeground(java.awt.Color.darkGray);
        backgroundLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        backgroundLabel.setText("Background Color:");

        defaultFontSizeLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        defaultFontSizeLabel.setForeground(java.awt.Color.darkGray);
        defaultFontSizeLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        defaultFontSizeLabel.setText("Font Size:");

        defaultFontColorLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        defaultFontColorLabel.setForeground(java.awt.Color.darkGray);
        defaultFontColorLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        defaultFontColorLabel.setText("Font Color:");

        defaultFontLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        defaultFontLabel.setForeground(java.awt.Color.darkGray);
        defaultFontLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        defaultFontLabel.setText("Display Font:");

        defaultFontColorButton.setFont(new java.awt.Font("Tahoma", 0, 12));
        defaultFontColorButton.setText("color");
        defaultFontColorButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                defaultFontColorButtonActionPerformed(evt);
            }
        });

        defaultBackgroundButton.setFont(new java.awt.Font("Tahoma", 0, 12));
        defaultBackgroundButton.setText("color");
        defaultBackgroundButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                defaultBackgroundButtonActionPerformed(evt);
            }
        });

        cboDefaultSize.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "8pt", "9pt", "10pt", "12pt", "14pt", "16pt", "18pt", "20pt" }));

        jLabel2.setText("Choose the default settings for text on your screen: ");

        defaultFontColorShow.setOpaque(true);

        defaultBkgndColorShow.setOpaque(true);

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel3.setText("Chat Buffer Size:");

        buffersize.setText("100");

        javax.swing.GroupLayout defaultPanelLayout = new javax.swing.GroupLayout(defaultPanel);
        defaultPanel.setLayout(defaultPanelLayout);
        defaultPanelLayout.setHorizontalGroup(
            defaultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(defaultPanelLayout.createSequentialGroup()
                .addGroup(defaultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(defaultPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(defaultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(defaultPanelLayout.createSequentialGroup()
                                .addGroup(defaultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(defaultFontSizeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)
                                    .addComponent(backgroundLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(defaultFontColorLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)
                                    .addComponent(defaultFontLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(defaultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(defaultFontComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(defaultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addGroup(defaultPanelLayout.createSequentialGroup()
                                            .addGroup(defaultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(cboDefaultSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(defaultFontColorButton))
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(defaultFontColorShow, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, defaultPanelLayout.createSequentialGroup()
                                            .addComponent(defaultBackgroundButton)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(defaultBkgndColorShow, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addGap(1207, 1207, 1207))
                            .addComponent(jLabel2)
                            .addComponent(overwriteCheckBox)))
                    .addGroup(defaultPanelLayout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(buffersize, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        defaultPanelLayout.setVerticalGroup(
            defaultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(defaultPanelLayout.createSequentialGroup()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(defaultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(defaultFontComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(defaultFontLabel))
                .addGroup(defaultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(defaultPanelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(defaultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cboDefaultSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(defaultFontSizeLabel))
                        .addGap(6, 6, 6)
                        .addGroup(defaultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(defaultFontColorButton)
                            .addComponent(defaultFontColorLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(defaultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(defaultBackgroundButton)
                            .addComponent(backgroundLabel)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, defaultPanelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(defaultFontColorShow, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(defaultBkgndColorShow, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(overwriteCheckBox)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
                .addGroup(defaultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(buffersize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        restoreDefaults.setText("Restore to Default");
        restoreDefaults.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                restoreDefaultsActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(defaultPanel, 0, 380, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(titleLabel)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(saveButton)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(restoreDefaults)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(cancelButton))
                                .addComponent(chatPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(titleLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(chatPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(13, 13, 13)
                .addComponent(defaultPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(saveButton)
                    .addComponent(cancelButton)
                    .addComponent(restoreDefaults))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * When user clicks restore defaults this method puts the settings back to the code defaults.
     * @param evt restore default button event
     */
    private void restoreDefaultsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_restoreDefaultsActionPerformed
        // Restore all settings to defaults
        this.chatFontComboBox.setSelectedItem("Arial");
        this.cboChatSize.setSelectedItem("12pt");
        chatColor = Color.black;
        this.chatColorShow.setBackground(chatColor);
        defaultColor = Color.black;
        this.defaultFontColorShow.setBackground(defaultColor);
        defaultBackgroundColor = Color.white;
        this.defaultBkgndColorShow.setBackground(defaultBackgroundColor);
        this.defaultFontComboBox.setSelectedItem("Arial");
        this.cboDefaultSize.setSelectedItem("12pt");
        this.overwriteCheckBox.setSelected(false);
    }//GEN-LAST:event_restoreDefaultsActionPerformed

    
/**
     * Sets all the options to stored values when the window is opened.
     * @param evt window opened event
     */
    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // Load in user defined chat settings
        this.chatFontComboBox.setSelectedItem(tempMain.theSettings.chatFont);
        this.cboChatSize.setSelectedItem(tempMain.theSettings.chatSize);
        this.chatColorShow.setBackground(makeColor(tempMain.theSettings.talkColor));
        this.defaultFontComboBox.setSelectedItem(tempMain.theSettings.displayFont);
        this.cboDefaultSize.setSelectedItem(tempMain.theSettings.displaySize);
        this.defaultFontColorShow.setBackground(makeColor(tempMain.theSettings.defaultColor));
        this.defaultBkgndColorShow.setBackground(makeColor(tempMain.theSettings.backColor));
        this.overwriteCheckBox.setSelected(tempMain.theSettings.overwrite);
        this.buffersize.setText(Integer.toString(tempMain.gui.buffer.getsize()));
    }//GEN-LAST:event_formWindowOpened

    
    /**
     * Converts a RGB class color to a Color object.
     * @param color an RGB class color (RGB is contained in DisplaySettings)
     * @return a Color object equal to the RGB color
     */
    private Color makeColor(RGB color) 
    {
        // Converts a String represented color to a Color object
        Color c;
        c = new Color(color.red, color.green, color.blue);
        
        return c;
    }
    
    
    /**
     * When user hits button to choose background color open color chooser, get their choice, and set defaultBkgndColorShow to it.
     * @param evt defaultBackground button event
     */
    private void defaultBackgroundButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_defaultBackgroundButtonActionPerformed
        // Pick a color for the chat defaultBackgroundColor color
        Color c = new Color( tempMain.theSettings.backColor.red, tempMain.theSettings.backColor.green, tempMain.theSettings.backColor.blue);
        Color returnColor = JColorChooser.showDialog( null , null, c);
        
        if (returnColor != null)
        {
            defaultBackgroundColor = returnColor;
        }
        else
        {
            defaultBackgroundColor = c;
        }
        
        this.defaultBkgndColorShow.setBackground(defaultBackgroundColor);
    }//GEN-LAST:event_defaultBackgroundButtonActionPerformed

    
/**
     * When user hits button to choose default font folor open color chooser, get their choice, and set defaultFontColorShow to it.
     * @param evt defaultFontColor button event
     */
    private void defaultFontColorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_defaultFontColorButtonActionPerformed
        // Pick a color for the chat foreground color
        Color c = new Color( tempMain.theSettings.defaultColor.red, tempMain.theSettings.defaultColor.green, tempMain.theSettings.defaultColor.blue);
        Color returnColor = JColorChooser.showDialog( null , null, c);
        
        if (returnColor != null)
        {
            defaultColor = returnColor;
        }
        else
        {
            defaultColor = c;
        }
        
        this.defaultFontColorShow.setBackground(defaultColor);
    }//GEN-LAST:event_defaultFontColorButtonActionPerformed

    
/**
     * When user hits button to choose chat color open color chooser, get their choice, and set chatColorShow to it.
     * @param evt chatColor button event
     */
    private void chatColorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chatColorButtonActionPerformed
// TODO add your handling code here:
        Color c = new Color( tempMain.theSettings.talkColor.red, tempMain.theSettings.talkColor.green, tempMain.theSettings.talkColor.blue);
        Color returnColor = JColorChooser.showDialog( null , null, c);
        
        if (returnColor != null)
        {
            chatColor = returnColor;
        }
        else
        {
            chatColor = c;
        }
        
        this.chatColorShow.setBackground(chatColor);
    }//GEN-LAST:event_chatColorButtonActionPerformed

 
    
/**
     * Stores the changed settings and saves a copy to file.
     * @param evt Save button event.
     */
    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        
        tempMain.theSettings.chatFont = this.chatFontComboBox.getSelectedItem().toString();
        tempMain.theSettings.chatSize = this.cboChatSize.getSelectedItem().toString();
        if( chatColor != null )
        {
            tempMain.theSettings.talkColor.red = chatColor.getRed();
            tempMain.theSettings.talkColor.green = chatColor.getGreen();
            tempMain.theSettings.talkColor.blue = chatColor.getBlue(); 
        }
                
        tempMain.theSettings.displayFont = this.defaultFontComboBox.getSelectedItem().toString();
        tempMain.theSettings.displaySize = this.cboDefaultSize.getSelectedItem().toString();
        
        if( defaultColor != null )
        {
            tempMain.theSettings.defaultColor.red = defaultColor.getRed();
            tempMain.theSettings.defaultColor.green = defaultColor.getGreen();
            tempMain.theSettings.defaultColor.blue = defaultColor.getBlue();
        }
        
        if( defaultBackgroundColor != null )
        {
            tempMain.theSettings.backColor.red = defaultBackgroundColor.getRed();
            tempMain.theSettings.backColor.green = defaultBackgroundColor.getGreen();
            tempMain.theSettings.backColor.blue = defaultBackgroundColor.getBlue();
        }
        
        tempMain.theSettings.overwrite = this.overwriteCheckBox.isSelected();
        tempMain.gui.buffer.setsize(Integer.parseInt(buffersize.getText()));
        
        
        if( !displaySize.isEmpty() )
        {
            tempMain.theSettings.displaySize = displaySize;
        }
        if( !chatSize.isEmpty() )
        {
            tempMain.theSettings.chatSize = chatSize;
        }
             
        
        // Save the profile to file
        String saveLocation = "fontSettings.txt";

        FileOutputStream out; // declare a file output object
        PrintStream p; // declare a print stream object

        try {
            // Create a new file output stream
            //  connected to "saveLocation" path
            out = new FileOutputStream(saveLocation);

            // Connect print stream to the output stream
            p = new PrintStream(out);

            // Write profile information to file
            p.println (tempMain.theSettings.chatFont);
            p.println (tempMain.theSettings.chatSize);
            p.println (tempMain.theSettings.talkColor.red);
            p.println (tempMain.theSettings.talkColor.green);
            p.println (tempMain.theSettings.talkColor.blue);
            p.println (tempMain.theSettings.displayFont);
            p.println (tempMain.theSettings.displaySize);
            p.println (tempMain.theSettings.defaultColor.red);
            p.println (tempMain.theSettings.defaultColor.green);
            p.println (tempMain.theSettings.defaultColor.blue);
            p.println (tempMain.theSettings.backColor.red);
            p.println (tempMain.theSettings.backColor.green);
            p.println (tempMain.theSettings.backColor.blue);
            p.println (tempMain.theSettings.overwrite);
            p.println (buffersize.getText());

            p.close();
        }
        catch (Exception e)
        {
            System.err.println (e.getMessage());
        }
        
        this.setVisible(false);
    }//GEN-LAST:event_saveButtonActionPerformed

    
/**
     * Hides the window when the Cancel button is selected.
     * @param evt Cancel button event.
     */
    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        // Hide form
        this.setVisible(false);
    }//GEN-LAST:event_cancelButtonActionPerformed

        
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel backgroundLabel;
    private javax.swing.JTextField buffersize;
    private javax.swing.JButton cancelButton;
    private javax.swing.JComboBox cboChatSize;
    private javax.swing.JComboBox cboDefaultSize;
    private javax.swing.JButton chatColorButton;
    private javax.swing.JLabel chatColorLabel;
    private javax.swing.JLabel chatColorShow;
    private javax.swing.JComboBox chatFontComboBox;
    private javax.swing.JLabel chatFontLabel;
    private javax.swing.JPanel chatPanel;
    private javax.swing.JLabel chatSizeLabel;
    private javax.swing.JButton defaultBackgroundButton;
    private javax.swing.JLabel defaultBkgndColorShow;
    private javax.swing.JButton defaultFontColorButton;
    private javax.swing.JLabel defaultFontColorLabel;
    private javax.swing.JLabel defaultFontColorShow;
    private javax.swing.JComboBox defaultFontComboBox;
    private javax.swing.JLabel defaultFontLabel;
    private javax.swing.JLabel defaultFontSizeLabel;
    private javax.swing.JPanel defaultPanel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JCheckBox overwriteCheckBox;
    private javax.swing.JButton restoreDefaults;
    private javax.swing.JButton saveButton;
    private javax.swing.JLabel titleLabel;
    // End of variables declaration//GEN-END:variables
    
}
